package com.qiwo.common.utils;

import com.alibaba.fastjson.JSON;
import org.apache.shiro.codec.Base64;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

public class MD5Utils {
	private static final String SALT = "1qazxsw2";

	private static final String ALGORITH_NAME = "md5";

	private static final int HASH_ITERATIONS = 2;

	public static String encrypt(String pswd) {
		String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(SALT), HASH_ITERATIONS).toHex();
		return newPassword;
	}

	public static String encrypt(String username, String pswd) {
		String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(username + SALT),
				HASH_ITERATIONS).toHex();
		return newPassword;
	}

	public static String enCodeBase64(String pswd) {

		return Base64.encodeToString(pswd.getBytes());
		// String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(SALT), HASH_ITERATIONS).toHex();
		// return newPassword;
	}

	public static String decodeBase64(String pswd) {
		return  Base64.decodeToString(pswd);
	}

	public static void main(String[] args) {
		/*System.out.println(encrypt("admin", "admin123"));*/
		String aa="{\"urls\":\"113.10.156.215,www.by-ekobo.cn\",\"date\":\"2018-11-28\"}";
		JSON.parseObject(aa);
		System.out.println(MD5Utils.enCodeBase64("{\"urls\":\"113.10.156.215,www.by-ekobo.cn,47.106.36.54\",\"date\":\"2018-12-28\"}"));
	}

}
